#ifndef MY_HEADER_H
#define MY_HEADER_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <stdbool.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <fcntl.h>
#include <pwd.h>
#include <grp.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <signal.h>
#include <sys/time.h>
#include <pthread.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/epoll.h>
#include <syslog.h>
#include <sys/sendfile.h>
#include <crypt.h>
#include <shadow.h>


// 调试宏定义开关
// 开发时定义为1，发布时定义为0
#define DEBUG_MODE 1
#if DEBUG_MODE
    #define DEBUG_PRINT(fmt, ...) printf("[DEBUG] %s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#else
    #define DEBUG_PRINT(fmt, ...) do {} while(0)
#endif

// 正常日志记录，正常函数调用的，平时用这个！
#define LOG(msg) {syslog(LOG_INFO,"<INFO>:FILE = %s,FUNCTION = %s,LINE = %d %s.\n",__FILE__,__FUNCTION__,__LINE__,msg);}
// 错误日志记录，给每个检查调用的
#define LOG_CHECK {syslog(LOG_ERR,"<ERROR>:FILE = %s,FUNCTION = %s,LINE = %d something wrong!\n",__FILE__,__FUNCTION__,__LINE__);}

// 检查命令行参数数量是否符合预期
#define ARGS_CHECK(argc, expected) \
    do { \
        if ((argc) != (expected)) { \
            LOG_CHECK;\
            fprintf(stderr, "args num error!\n"); \
            exit(1); \
        } \
    } while (0)

// 检查返回值是否是错误标记,若是则打印msg和错误信息
#define ERROR_CHECK(ret, error_flag, msg) \
    do { \
        if ((ret) == (error_flag)) { \
            LOG_CHECK;\
            perror(msg); \
            exit(1); \
        } \
    } while (0)

#define THREAD_ERROR_CHECK(ret,msg){if(ret != 0){fprintf(stderr,"%s:%s",msg,strerror(ret));}LOG_CHECK();}

#endif
